package com.linwen.javase.file;

import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

/**
 * @author : linwen
 * @date : 下午10:41 2021/9/15
 */
public class URLTest {
    @Test
    public void test1() throws IOException {
        ArrayList<URL> urls = new ArrayList<URL>();
        urls.add(new URL("http://img.netbian.com/file/2021/0712/smalle5fc12454e926d02fe296b0ec0cfe1601626104135.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0704/smallec94e84ef914645730e86273c38d8fb61625407371.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0704/small7d2827093fb6b81fe8d3db3478ff00731625407302.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0704/small29d6e34c27241197a2fa7934e705b8d31625407251.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0621/smallcae13b82615b37c430407055ca7b4dbf1624288432.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0621/small924b0c7adfce7fbb098ac0fce296daf41624288317.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0621/smallfe57ddf28398a4903c2b950fe467481e1624288157.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0621/smallda84ff00b27be6393b857bb8d9b663c11624288008.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0621/smalle99bc6ce53e90278bac3fba5d1effce21624287976.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0621/small73413c85052b2b12aa705316fdcb62e11624287932.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0413/small3ae3c6ab16cb5e70b02a8cd97ae134a51618327237.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0413/small9017db6f8933aaaf70dc54513782ba931618327123.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0330/small06b302fd4866aa8179474227bb4f58f61617116022.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0304/small5a70780670c131a773af71466e7ba4da1614788360.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0217/smallcaf4fc9b69597bcfc00dd999aa20cfcd1613569890.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0217/small6db6cbaeea25233f21c0a3f1d6cf3f201613569851.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0203/small88a0dc76066816539779d61c052db6ae1612367735.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0217/small607a2107b1135dcd365e152176810a8b1613569798.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2021/0125/small4c701c71b6637961836a23f612ac34d21611588552.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2020/1229/smalle73c58325cbdc1531000cf2c9346edac1609248949.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2020/0927/small9fab60268737632546335b98af95a3871601217239.jpg"));
        urls.add(new URL("http://img.netbian.com/file/2020/0625/small8290bc3ded3e5d39b366d08ec752744b1593016760.jpg"));

        HttpURLConnection urlConnection = null;
        InputStream inputStream = null;
        FileOutputStream outputStream = null;
        for (int i = 0; i < urls.size(); i++) {
            urlConnection = (HttpURLConnection) urls.get(i).openConnection();
            urlConnection.connect();
            inputStream = urlConnection.getInputStream();
            outputStream = new FileOutputStream("壁纸//王者壁纸"+i+".jpg");
            byte[] buffer = new byte[1024];
            int len;
            while ((len = inputStream.read(buffer))!=-1){
                outputStream.write(buffer,0,len);
            }
        }
        outputStream.close();
        inputStream.close();

    }
}
